#Boa:Dialog:cheques

import wx
import wx.grid
import wx.lib.masked.numctrl
import wx.calendar
import consultasBD
import Mensaje

def create(parent):
    return cheques(parent)

[wxID_CHEQUES, wxID_CHEQUESCOBRO, wxID_CHEQUESEMISION, wxID_CHEQUESGRID1, 
 wxID_CHEQUESGUARDARCHEQUE, wxID_CHEQUESIMPORTE, wxID_CHEQUESINDESTINATARIO, 
 wxID_CHEQUESINHOY, wxID_CHEQUESINIMPUESTOCHEQUE, wxID_CHEQUESINMES, 
 wxID_CHEQUESINNROCHEQUE, wxID_CHEQUESINSEMANA, wxID_CHEQUESINTOTALES, 
 wxID_CHEQUESSTATICLINE1, wxID_CHEQUESSTATICTEXT1, wxID_CHEQUESSTATICTEXT10, 
 wxID_CHEQUESSTATICTEXT12, wxID_CHEQUESSTATICTEXT2, wxID_CHEQUESSTATICTEXT3, 
 wxID_CHEQUESSTATICTEXT4, wxID_CHEQUESSTATICTEXT5, wxID_CHEQUESSTATICTEXT6, 
 wxID_CHEQUESSTATICTEXT7, wxID_CHEQUESSTATICTEXT8, wxID_CHEQUESSTATICTEXT9, 
] = [wx.NewId() for _init_ctrls in range(25)]

class cheques(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_CHEQUES, name='cheques', parent=prnt,
              pos=wx.Point(349, 198), size=wx.Size(511, 396),
              style=wx.DEFAULT_DIALOG_STYLE,
              title=u'Administraci\xf3n de Bancos')
        self.SetClientSize(wx.Size(495, 360))
        self.SetToolTipString('cheques')

        self.emision = wx.DatePickerCtrl(id=wxID_CHEQUESEMISION, name='infecha',
              parent=self, pos=wx.Point(112, 8), size=wx.Size(96, 21),
              style=wx.DP_DROPDOWN)

        self.staticText1 = wx.StaticText(id=wxID_CHEQUESSTATICTEXT1,
              label='Cheque Nro:', name='staticText1', parent=self,
              pos=wx.Point(288, 8), size=wx.Size(62, 13), style=0)

        self.innrocheque = wx.TextCtrl(id=wxID_CHEQUESINNROCHEQUE,
              name='innrocheque', parent=self, pos=wx.Point(352, 8),
              size=wx.Size(120, 21), style=0, value='')

        self.importe = wx.lib.masked.numctrl.NumCtrl(id=wxID_CHEQUESIMPORTE,
              name='importe', parent=self, pos=wx.Point(112, 45),
              size=wx.Size(78, 22), style=wx.TE_LEFT, value=0)
        self.importe.SetGroupChar(',')
        self.importe.SetDecimalChar('.')
        self.importe.SetFractionWidth(2)
        self.importe.SetDescription('')
        self.importe.SetDefaultValue('')
        self.importe.SetInsertionPoint(5)
        self.importe.SetHelpText('')
        self.importe.SetIntegerWidth(5)

        self.staticText2 = wx.StaticText(id=wxID_CHEQUESSTATICTEXT2,
              label='Importe: ', name='staticText2', parent=self,
              pos=wx.Point(24, 40), size=wx.Size(46, 13), style=0)

        self.staticText3 = wx.StaticText(id=wxID_CHEQUESSTATICTEXT3,
              label=u'Fecha de emisi\xf3n:', name='staticText3', parent=self,
              pos=wx.Point(8, 8), size=wx.Size(87, 13), style=0)

        self.staticText4 = wx.StaticText(id=wxID_CHEQUESSTATICTEXT4,
              label='Fecha de Cobro:', name='staticText4', parent=self,
              pos=wx.Point(8, 80), size=wx.Size(81, 13), style=0)

        self.staticText5 = wx.StaticText(id=wxID_CHEQUESSTATICTEXT5,
              label='Destinatario:', name='staticText5', parent=self,
              pos=wx.Point(288, 40), size=wx.Size(63, 13), style=0)

        self.indestinatario = wx.TextCtrl(id=wxID_CHEQUESINDESTINATARIO,
              name='indestinatario', parent=self, pos=wx.Point(352, 40),
              size=wx.Size(120, 21), style=0, value='')

        self.cobro = wx.DatePickerCtrl(id=wxID_CHEQUESCOBRO, name='cobro',
              parent=self, pos=wx.Point(112, 80), size=wx.Size(96, 21),
              style=wx.DP_DROPDOWN)

        self.staticLine1 = wx.StaticLine(id=wxID_CHEQUESSTATICLINE1,
              name='staticLine1', parent=self, pos=wx.Point(0, 120),
              size=wx.Size(480, 2), style=0)

        self.staticText6 = wx.StaticText(id=wxID_CHEQUESSTATICTEXT6,
              label='Total que entra hoy:', name='staticText6', parent=self,
              pos=wx.Point(8, 128), size=wx.Size(100, 13), style=0)

        self.staticText7 = wx.StaticText(id=wxID_CHEQUESSTATICTEXT7,
              label='Total de esta SEMANA:', name='staticText7', parent=self,
              pos=wx.Point(8, 152), size=wx.Size(112, 13), style=0)

        self.staticText8 = wx.StaticText(id=wxID_CHEQUESSTATICTEXT8,
              label='Total de este MES:', name='staticText8', parent=self,
              pos=wx.Point(280, 128), size=wx.Size(91, 13), style=0)

        self.staticText9 = wx.StaticText(id=wxID_CHEQUESSTATICTEXT9,
              label='Total pagado con cheques:', name='staticText9',
              parent=self, pos=wx.Point(248, 152), size=wx.Size(131, 13),
              style=0)

        self.staticText10 = wx.StaticText(id=wxID_CHEQUESSTATICTEXT10,
              label='Total pagado en Impuesto al cheque:', name='staticText10',
              parent=self, pos=wx.Point(296, 184), size=wx.Size(180, 13),
              style=0)

        self.inmes = wx.TextCtrl(id=wxID_CHEQUESINMES, name='inmes',
              parent=self, pos=wx.Point(392, 128), size=wx.Size(80, 21),
              style=0, value='0')
        self.inmes.SetEditable(False)

        self.insemana = wx.TextCtrl(id=wxID_CHEQUESINSEMANA, name='insemana',
              parent=self, pos=wx.Point(144, 152), size=wx.Size(80, 21),
              style=0, value='0')
        self.insemana.SetEditable(False)

        self.inHoy = wx.TextCtrl(id=wxID_CHEQUESINHOY, name='inHoy',
              parent=self, pos=wx.Point(144, 128), size=wx.Size(80, 21),
              style=0, value='0')
        self.inHoy.SetEditable(False)

        self.inimpuestocheque = wx.TextCtrl(id=wxID_CHEQUESINIMPUESTOCHEQUE,
              name='inimpuestocheque', parent=self, pos=wx.Point(336, 208),
              size=wx.Size(80, 21), style=0, value='0')
        self.inimpuestocheque.SetEditable(False)

        self.intotales = wx.TextCtrl(id=wxID_CHEQUESINTOTALES, name='intotales',
              parent=self, pos=wx.Point(392, 152), size=wx.Size(80, 21),
              style=0, value='0')
        self.intotales.SetEditable(False)

        self.staticText12 = wx.StaticText(id=wxID_CHEQUESSTATICTEXT12,
              label='Mayores COBROS DEL MES:', name='staticText12', parent=self,
              pos=wx.Point(16, 184), size=wx.Size(135, 13), style=0)

        self.grid1 = wx.grid.Grid(id=wxID_CHEQUESGRID1, name='grid1',
              parent=self, pos=wx.Point(16, 200), size=wx.Size(272, 144),
              style=0)

        self.guardarCheque = wx.Button(id=wxID_CHEQUESGUARDARCHEQUE,
              label='Guardar NUEVO CHEQUE', name='guardarCheque', parent=self,
              pos=wx.Point(288, 72), size=wx.Size(144, 32), style=0)
        self.guardarCheque.Bind(wx.EVT_BUTTON, self.OnGuardarChequeButton,
              id=wxID_CHEQUESGUARDARCHEQUE)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.cargaValores()
        self.ranking()
    
    def cargaValores(self):
        pass
        
        
        
        
    def ranking(self):
        self.grid1.CreateGrid(5,2)
        columnas2 =['Fecha','Valor']
        for i in range(len(columnas2)-1,-1,-1): 
            self.grid1.SetColLabelValue(i, columnas2[i])
            
        self.grid1.AutoSizeColumn(0,True)
        self.grid1.AutoSizeColumn(1,True)
        

    def OnGuardarChequeButton(self, event):
        import utiles
        print "fecha",str(self.emision.Value)
        print self.cobro.Value
        fechaemision= utiles.formatear_fecha(self.emision.Value)
        chequenro=self.innrocheque.Value
        importe= self.importe.Value.replace(",","")
        fechacobro= utiles.formatear_fecha(self.cobro.Value)
        destinatario= self.indestinatario.Value
        tablaSQL = "bancos(fechaemision,chequenro,importe,fechacobro,destinatario,acreditado)"
        camposSQL = "('"+str(fechaemision)+"','"+chequenro+"',"+str(importe)+",'"+str(fechacobro)+"','"+str(destinatario)+"','')"
        self.idventa = consultasBD.executaInsertSQL(self,tablaSQL,camposSQL)
        dlg = Mensaje.Mensaje(self,"Se cargo Correctamente el CHEQUE")
        try:
            dlg.ShowModal()
        finally:
            dlg.Destroy()
        self.Close()
            
